var t = getApp();

Page({
    data: {
        searchVal: "",
        winHeight: "",
        currentTab: 0,
        scrollLeft: 0,
        picLayer: !1,
        list: [],
        listId: 0,
        isChoose: !1,
        chooseData: {},
        bigPicUrl: "",
        lastId: null,
        nextId: null,
        index: 0,
        pageData: [],
        server: t.server,
        serverUrl: t.serverUrl,
        showQRShare: t.showQRShare,
        showPrice: t.showPrice,
        cates: [],
        currCate: 0
    },
    onLoad: function(t) {
        console.log("options", JSON.parse(t.data)), this.setData({
            cates: JSON.parse(t.data)
        });
    },
    loadCates: function(a, e, r) {
        t.request({
            url: t.server + "/productApi/getProductCatList",
            method: "POST",
            data: {
                token: t.token
            },
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {}
        });
    },
    swichCate: function(t) {
        this.setData({
            "options.cateId": this.data.cates[t.currentTarget.dataset.index].id,
            currCate: t.currentTarget.dataset.index
        });
    },
    loadPrds: function() {
        var a = this;
        t.request({
            url: t.server + "/productApi/getProductCatInfo",
            method: "POST",
            data: {
                token: t.token,
                page_size: 99999,
                cur_page: 1
            },
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                var e = t.data.result.product, r = !0, o = !1, s = void 0;
                try {
                    for (var d, c = a.data.cates[Symbol.iterator](); !(r = (d = c.next()).done); r = !0) {
                        var i = d.value, n = !0, u = !1, l = void 0;
                        try {
                            for (var p, h = e[Symbol.iterator](); !(n = (p = h.next()).done); n = !0) {
                                var f = p.value;
                                f.category_id === i.id && i.prds.push(f);
                            }
                        } catch (t) {
                            u = !0, l = t;
                        } finally {
                            try {
                                !n && h.return && h.return();
                            } finally {
                                if (u) throw l;
                            }
                        }
                    }
                } catch (t) {
                    o = !0, s = t;
                } finally {
                    try {
                        !r && c.return && c.return();
                    } finally {
                        if (o) throw s;
                    }
                }
                a.setData({
                    cates: a.data.cates
                });
            }
        });
    },
    onShow: function() {},
    choose: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/pages/products/detail/detail?id=" + a
        });
    },
    choose1: function(a) {
        var e = this;
        console.log(a), t.request({
            url: t.server + "/productApi/getProductInfo",
            method: "POST",
            data: {
                id: a.currentTarget.dataset.id
            },
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                console.log(t), e.setData({
                    picLayer: !0,
                    index: a.currentTarget.dataset.x,
                    chooseData: t.data.result.product,
                    lastId: 0 === t.data.result.product.last_id ? null : t.data.result.product.last_id,
                    nextId: 0 === t.data.result.product.next_id ? null : t.data.result.product.next_id,
                    bigPicUrl: 0 !== t.data.result.product.attr[0].length ? t.data.result.product.attr[0].url : ""
                });
            }
        });
    },
    offPicLayer: function() {
        this.setData({
            picLayer: !1
        });
    },
    switchTab: function(t) {
        this.setData({
            "options.cateId": this.data.cates[t.detail.current].id,
            listId: this.data.cates[t.detail.current].id,
            currCate: t.detail.current
        });
    },
    nextChoose: function(a) {
        var e = a.target.dataset.id;
        if (null !== e) {
            var r = this;
            t.request({
                url: t.server + "/productApi/getProductInfo",
                method: "POST",
                data: {
                    id: e
                },
                header: {
                    "content-type": "application/x-www-form-urlencoded"
                },
                success: function(t) {
                    console.log(t), r.setData({
                        chooseData: t.data.result.product,
                        lastId: 0 === t.data.result.product.last_id ? null : t.data.result.product.last_id,
                        nextId: 0 === t.data.result.product.next_id ? null : t.data.result.product.next_id,
                        bigPicUrl: 0 !== t.data.result.product.attr.length ? t.data.result.product.attr[0].url : ""
                    });
                }
            });
        }
    },
    chooseColor: function(t) {
        var a = this;
        this.setData({
            bigPicUrl: a.data.chooseData.attr[t.currentTarget.dataset.colorx].url
        });
    },
    toPlay: function(t) {
        wx.navigateTo({
            url: "/pages/play/play?id=" + this.data.chooseData.id
        });
    },
    onShareAppMessage: function() {}
});